package hello;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;

@EnableApolloConfig
@RestController
@EnableAutoConfiguration
public class Hello {

	private static final Logger logger = LoggerFactory.getLogger(Hello.class);
	
	@Value("${env:dev}")
	private String env;
	
	@Value("${my.env}")
	private String myEnv;
	
	@RequestMapping("/hello")
	public String hello() {
		String hostName = null;
		try {
			hostName = InetAddress.getLocalHost().getHostName();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		logger.info("request hello, env: {}, myEnv: {}, hostName: {}", env, myEnv, hostName);
		return "Hello!";
	}
	
	public static void main(String[] args) {
		new SpringApplication(Hello.class).run(args);
	}

}
